package cn.dt70.service.impl;

import cn.dt70.dao.aqbRecept.AqbReceptMapper;
import cn.dt70.pojo.AqbRecept;
import cn.dt70.service.AqbReceptService;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class AqbReceptServiceImpl implements AqbReceptService {

    private static final Logger LOGGER = Logger.getLogger(AqbReceptServiceImpl.class);

    @Resource
    private AqbReceptMapper aqbReceptMapper;

    @Override
    public boolean addRecept(AqbRecept aqbRecept) throws Exception {
        int row = 0;

        try {
            row = aqbReceptMapper.addRecept(aqbRecept);
            if(row!=1){
                LOGGER.debug("添加承接记录失败");
                return false;
            }else{
                LOGGER.debug("添加承接记录成功");
                return true;
            }
        } catch (Exception e) {
             LOGGER.error("添加承接记录异常！");
            return false;
        }

    }

    @Override
    public List<AqbRecept> findReceptById(Integer id, Integer querytime) throws Exception {
        List<AqbRecept> receptList = new ArrayList<>();

        try {
            receptList = aqbReceptMapper.queryReceptById(id,querytime);
            if(receptList.size()<=0){
                LOGGER.debug("承接查询为空");
            }else{
                LOGGER.debug("承接查询成功");
            }
        } catch (Exception e) {
            LOGGER.error("承接查询异常"+e.getMessage());
        }
        return receptList;
    }

    @Override
    public List<AqbRecept> findReceptByIdForTime(Integer id, Date begin, Date end) throws Exception {
        List<AqbRecept> receptList = new ArrayList<>();

        try {
            receptList = aqbReceptMapper.queryReceptByIdForTime(id,begin,end);
            if(receptList.size()<=0){
                LOGGER.debug("承接查询为空");
            }else{
                LOGGER.debug("承接查询成功");
            }
        } catch (Exception e) {
            LOGGER.error("承接查询异常"+e.getMessage());
        }
        return receptList;
    }
}
